package com.example.fresheveryday.controller;


import com.example.fresheveryday.po.CategorySaleDTO;
import com.example.fresheveryday.po.Productcategory;
import com.example.fresheveryday.restful.JsonResult;
import com.example.fresheveryday.service.ProductcategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ll
 * @since 2023-07-5
 */
@RestController
@RequestMapping("/productcategory")
public class ProductcategoryController {
    @Autowired
    ProductcategoryService productcategoryService;
    @RequestMapping("/list")
    public List<Productcategory> list(){
        System.out.println(productcategoryService.list());
        return productcategoryService.list();
    }
    @RequestMapping("/addorupdate")
    public JsonResult add(@RequestBody Productcategory productcategory){
        System.out.println("添加的类型");
        System.out.println(productcategory);
        productcategoryService.saveOrUpdate(productcategory);
        return JsonResult.success("success");
    }
    @RequestMapping("/getbyid")
    public Productcategory getbyid(int id){
        return productcategoryService.getById(id);
    }

    @RequestMapping("/del")
    public JsonResult del(int id){
        productcategoryService.removeById(id);
        return JsonResult.success("success");
    }
    @RequestMapping("/getHomeProduct")
    public List<Productcategory> getlist(){
        return productcategoryService.getHomeProduct();
    }

    @RequestMapping("/getSale")
    public List<CategorySaleDTO> get(){
        return productcategoryService.getByCategorySale();
    }
}
